package com.battle.service.repository.impl;

import cn.hutool.core.collection.CollectionUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.battle.pojo.entity.CaseBaseInfo;
import com.battle.pojo.vo.caseBaseInfo.CaseHomePageVo;
import com.battle.service.mapper.CaseBaseInfoMapper;
import com.battle.service.repository.in.CaseBaseInfoRepository;
import nirvana.core.repository.Repository;
import org.springframework.stereotype.Service;
import com.battle.pojo.dto.caseBaseInfo.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

/**
 * 【描 述】：
 * 【环 境】：J2SE
 * 【详 细】：
 */
@Service
public class CaseBaseInfoRepositoryImpl extends Repository<CaseBaseInfoMapper, CaseBaseInfo> implements CaseBaseInfoRepository {

    private final CaseBaseInfoMapper mapper;

    public CaseBaseInfoRepositoryImpl(CaseBaseInfoMapper mapper) {
        this.mapper = mapper;
    }

    /**
     * 搜索战例
     *
     * @param dto
     * @return
     */
    @Override
    public Page<CaseBaseInfo> selectCaseBaseInfo(SelectCaseBaseInfoDto dto) {
        if (dto.getIsDeleted() == null) dto.setIsDeleted(false);
        return mapper.selectCaseBaseInfo(dto);
    }

    @Override
    public Map<Long, CaseBaseInfo> getMap(List<Long> ids) {
        Map<Long, CaseBaseInfo> map = new HashMap<>();

        if (CollectionUtil.isNotEmpty(ids)) {
            List<CaseBaseInfo> list = listByIds(ids);
            if (CollectionUtil.isNotEmpty(list)) {
                map = list.stream().collect(Collectors.toMap(CaseBaseInfo::getId, pojo -> pojo));
            }
        }
        return map;
    }

    @Override
    public List<CaseHomePageVo> selectRecommendCaseList() {
        return mapper.selectRecommendCaseList();
    }

    @Override
    public List<CaseHomePageVo> selectBacklogCaseList() {
        return mapper.selectBacklogCaseList();
    }
}